﻿Public Class CLSPedidos
    Dim sql As String
    Dim objbanco As New CLSBanco

    Dim M_Ped_ID As Integer
    Dim M_Ped_CID As Integer
    Dim M_Ped_Dat As Date
    Dim M_Ped_DV As Date
    Dim M_Ped_DP As Date
    Dim M_Ped_SP As String


    Public Property ID() As Integer
        Get
            Return M_Ped_ID
        End Get
        Set(ByVal value As Integer)
            M_Ped_ID = value
        End Set
    End Property

    Public Property ID_Cliente() As Integer
        Get
            Return M_Ped_CID
        End Get
        Set(ByVal value As Integer)
            M_Ped_CID = value
        End Set
    End Property

    Public Property Data_Pedido() As Date
        Get
            Return M_Ped_Dat
        End Get
        Set(ByVal value As Date)
            M_Ped_Dat = value
        End Set
    End Property
    Public Property Data_Vencimento() As Date
        Get
            Return M_Ped_DV
        End Get
        Set(ByVal value As Date)
            M_Ped_DV = value
        End Set
    End Property
    Public Property Data_Pagamento() As Date
        Get
            Return M_Ped_DP
        End Get
        Set(ByVal value As Date)
            M_Ped_DP = value
        End Set
    End Property
    Public Property Situação_Pedido() As String
        Get
            Return M_Ped_SP
        End Get
        Set(ByVal value As String)
            M_Ped_SP = value
        End Set
    End Property

    Public Sub Gravar()
        '  sql = "insert into Pedidos " & _
        '    "(M_Ped_ID" & _
        '    ",M_Ped_CID" & _
        '    ",M_Ped_Dat" & _
        '    ",M_Ped_DV" & _
        '    ",M_Ped_DP" & _
        '    ",M_Ped_SP" & _
        '    ") values " & _                                     SEM AUTO NUMBER
        '    "(" M_Cli_ID & _
        '    ",'" & M_Cli_Nom & "'" & _
        '    ",'" & M_Cli_End & "'" & _
        '    ",'" & M_Cli_Bai & "'" & _
        '    ",'" & M_Cli_Tel & "'" & _
        '    "," & M_Cli_Cre & _
        '    ")"

        sql = "insert into Pedidos " & _
          "(Ped_CID" & _
          ",Ped_Dat" & _
          ",Ped_DV" & _
          ",Ped_DP" & _
          ",Ped_SP" & _
          ") values " & _
          "('" & M_Ped_CID & "'" & _
          ",'" & M_Ped_Dat & "'" & _
          ",'" & M_Ped_DV & "'" & _
          ",'" & M_Ped_DP & "'" & _
          ",'" & M_Ped_SP & "'" & _
          ")"
        objbanco.executar_comando(sql)
        ID = buscar_ultimo_codigo()

    End Sub

    Public Function excluir(ByVal meucliente As Integer) As Boolean
        sql = "delete from Pedidos where Cli_ID=" & meucliente
        objbanco.executar_comando(sql)
        Return True
    End Function

    Public Function LocalizarPorID(ByVal digiteID As Integer) As DataTable
        sql = "select * from Pedidos where Cli_ID = " & digiteID
        Dim objda As New OleDb.OleDbDataAdapter(sql, objbanco.objcon)
        Dim objds As New DataSet
        objda.Fill(objds)
        Return objds.Tables(0)
    End Function
    Public Function buscar_ultimo_codigo() As Integer
        sql = "select max(Ped_ID) from pedidos"
        Dim objda As New OleDb.OleDbDataAdapter(sql, objbanco.objcon)
        Dim objds As New DataSet
        objds.Tables.Clear()
        objda.Fill(objds)
        Return objds.Tables(0).Rows(0).Item(0)

    End Function
End Class
